<template>
	<div class="page-container">
  <el-dialog title="盘库托盘" width="90%"   :visible.sync="coreStockDetailViewVisible" 
     :close-on-click-modal="false" :before-close="handleClose"   @opened="findPage(1)" >
		<div class="gk-layout-container">
				<div class="gk-layout-header">
					<!--工具栏-->
					<s-query perms="core:coreStock"   @click="findPage" > 
							<el-form-item>
								<el-input v-model.trim="filters.locId" placeholder="请输入货位"></el-input>
							</el-form-item>
							<s-item v-model="filters.rareaId"></s-item>
							<s-dict name="stockStatus" v-model="filters.stockStatus"></s-dict>
							
					</s-query>
					
				</div>
				<div class="gk-layout-main" style="height:500px">
					<my-table :data="pageResult.content" :key="componentKey"    :loading="loading"  >
						<el-table-column :label="$t('action.desc')" width="50" fixed="left"  header-align="center" align="center">
							<template slot-scope="scope">   {{scope.$index+1}}   </template>
						</el-table-column> 
						<Column  width="300"  prop="boxCode" label="条码"    />
						<Column  prop="locId" label="储位"    :formatter= "selectionFormat"  />
						<Column  prop="status" label="状态"     :formatter= "selectionFormat" />
						<Column  prop="createTime" label="创建时间"     :formatter= "dateFormat" /> 
						<el-table-column    :label="$t('action.operation')" width="120">
							<template slot-scope="scope">
								<kt-button icon="fa fa-edit"  type="text"   label="编辑"  perms="core:coreStock:showDetail"    @click="handleShowDetail(scope.$index, scope.row)" />
							</template>
						</el-table-column>
					</my-table>
			</div>
			<div class="toolbar gk-layout-footer"  style="padding:10px;"> 
				<el-pagination layout="total, prev, pager, next, jumper"  @current-change="findPage"
							:current-page="filters.pageNum"
							:page-size="filters.pageSize"
							:total="pageResult.totalSize"
							style="float:right;">
				</el-pagination>
			</div> 
		</div>
		</el-dialog>
		<adjust-core-stock  :pkId="myParam.pkId"   :dialogVisible="stockViewDialogVisible"  :row=dataForm  @stockViewHidden="stockViewHidden" />
	
	</div>
</template>

<script>

	import KtButton from "@/views/Core/KtButton"
	import { format } from "@/utils/datetime"
	import { formatDay } from "@/utils/datetime"
	import Column from "@/views/Core/Column"
	import MyTable from "@/views/Core/MyTable" 
	import AdjustCoreStock from "./AdjustCoreStock"
    import ItemSelect from "@/views/Basic/Material/ItemSelect"
		import SItem from "@/components/Kj/SItem"
    import {  dictsFormat ,getItemName} from "@/utils/myUtil"
	   import SQuery from "@/components/Kj/SQuery" 
	      import SDict from "@/components/Kj/SDict"
	import XLSX from "xlsx";
	export default {
		name: 'AdjustPk',
		components: {
			KtButton,
			Column,
			MyTable,
			ItemSelect,SItem,
			AdjustCoreStock,SQuery,SDict
		},
		props: {
			myParam: Object,
			coreStockDetailViewVisible: {
				type: Boolean
			}
		 
		},
		data() {
			return {
				size: 'small',
				filters: {
					label: '',pageNum: 1, pageSize: 20 
				},
				loading:false,
			  
			 	componentKey:0,
		 
				pageResult: {},
				pageResultDetail: {}, 
				editDialogVisible: false, // 新增编辑界面是否显示
				stockViewDialogVisible:false,
				editLoading: false,  
				dataForm: { }
			}
		},
		methods: {
			// 获取分页数据
			findPage: function (data) {
				if(data!=-1){
					this.filters.pageNum=data	
				}
				this.filters.pkId =this.myParam.pkId  
				this.$api.coreStock.findPage(this.filters).then((res) => {
					this.pageResult = res.data
				}) 
			},
			// 获取明细数据
			findDetailPage: function (data) {
				this.$api.coreStock.GetListByStockId(data).then((res) => {
					this.pageResultDetail = { content: res.data }
				}) 
			},
			// 显示详情界面
			handleShowDetail: function (params,row) {
				this.dataForm = Object.assign({}, row)
				this.stockViewDialogVisible = true
			    this.componentKey += 1;  
			},
			stockViewHidden: function () { 
				 this.stockViewDialogVisible= false; // 新增编辑界面是否显示
			},
			handleChangePos: function (scope,row,direct) {
				row.dir=direct
				this.$api.coreStock.changeDetailPos(row).then((res) => {
					this.findDetailPage(this.dataForm)
				}) 
			},
			// 时间格式化
			dateFormat: function (row, column, cellValue, index) {
				return format(row[column.property])
			},
			dateFormatDay: function (row, column, cellValue, index) {
				return formatDay(row[column.property])
			},
			countFormat: function (row, column, cellValue, index) {
				return cellValue +dictsFormat( "units",row.unit)
			},
			itemFilter: function (row, column, cellValue, index) {
				return getItemName(cellValue)
			},
			 
			selectionFormat: function (row, column, cellValue, index) {
				let key = ""
				let propt = column.property;
				if (propt == "status" ) {
					key = "stockStatus"
				} else if (propt == "storeStatus") {
					key = "storeStatus"
				}else if (propt == "locked") {
					key = "isLocked"
				}else if (propt == "wh") {
					key = "wh"
				}
				return dictsFormat( key,cellValue);
			},
			handleClose: function () {
				this.$emit('coreStockClose', {})
			},
 
		},
		mounted() {
		 	this.findPage(1);
		}
	}
</script>

<style scoped>

</style>